Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): aware of version info from tauri config #9856

Merged
merged 6 commits into from
May 24, 2024

Conversation

mariotaku
Copy link
Contributor

This PR makes generated Android packages having the same versionName as it's defined in tauri.config.json, and providing 2 ways to define versionCode:

  1. Calculated: version.major * 1000000 + version.minor * 1000 + version.patch
  2. Overridden 1 by bundle > android > versionCode in tauri.config.json

@mariotaku mariotaku requested a review from a team as a code owner May 22, 2024 16:55
@mariotaku mariotaku force-pushed the feature/android-version-info branch from 3f2d261 to b602661 Compare May 22, 2024 16:56
core/tauri-build/src/mobile.rs Outdated Show resolved Hide resolved
core/tauri-build/src/mobile.rs Outdated Show resolved Hide resolved
write(&gradle_settings_path, gradle_settings).context("failed to write tauri.settings.gradle")?;

write(&app_build_gradle_path, app_build_gradle)
.context("failed to write tauri.build.gradle.kts")?;

write(&app_gradle_properties_path, app_gradle_properties)
.context("failed to write gradle.properties")?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.context("failed to write gradle.properties")?;
.context("failed to write tauri.properties")?;

tooling/cli/templates/mobile/android/app/.gitignore Outdated Show resolved Hide resolved
core/tauri-build/src/mobile.rs Outdated Show resolved Hide resolved
@amrbashir
Copy link
Member

Oh looks like you didn't sign your commits. You need to setup commit signing, then you can sign past commit like this for example.

@mariotaku mariotaku force-pushed the feature/android-version-info branch from b602661 to 1ec4cb5 Compare May 23, 2024 01:59
@mariotaku
Copy link
Contributor Author

Hello! I have updated & signed the commit.

@mariotaku mariotaku force-pushed the feature/android-version-info branch from 1ec4cb5 to 9a15520 Compare May 23, 2024 02:53
@mariotaku mariotaku force-pushed the feature/android-version-info branch from 9a15520 to a4b5331 Compare May 23, 2024 02:56
@mariotaku mariotaku requested a review from amrbashir May 23, 2024 04:23
write(&gradle_settings_path, gradle_settings).context("failed to write tauri.settings.gradle")?;

write(&app_build_gradle_path, app_build_gradle)
.context("failed to write tauri.build.gradle.kts")?;

write(&app_tauri_properties_path, app_tauri_properties)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe avoid writing if config.version is None and don't emit cargo:rerun either?

@amrbashir
Copy link
Member

Seems like you need to run cargo fmt and you're also missing documentation on version_code field and schema is not generated so run cargo -b tauri-config-schema to generate it,

@lucasfernog
Copy link
Member

nice one!

@lucasfernog lucasfernog merged commit fd2d7cf into tauri-apps:dev May 24, 2024
29 of 30 checks passed
Comment on lines +55 to +63
if let Some(version) = config.version.as_ref() {
app_tauri_properties.push(format!("tauri.android.versionName={}", version));
if let Some(version_code) = config.bundle.android.version_code.as_ref() {
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
} else if let Ok(version) = Version::parse(version) {
let version_code = version.major * 1000000 + version.minor * 1000 + version.patch;
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check the final version code here? Since it might be out of the valid range. For example, create-tauri-app will create with version 0.0.0 hence the VersionCode is 0 which is invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pewsheen This is a good catch! I think it can verified after line 60.

Copy link
Member

@amrbashir amrbashir May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fail with an error when building for android if versionCode is not specified in tauri.conf.json and app version is 0.0.0 but only in release mode. Similar to what we do when identifier is set to com.tauri.dev

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I've created a PR fro this: #9898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants